package minov.parser;

/**
 * This class is for arguments that have floats as their parameters.
 *
 */
public class FloatArgument extends MultipleValueArgument<Double> {

   /**
    * Constructs argument that parses float values.<br>
    * Example:
    * 
    * <pre>
    * floatArgument = new FloatArgument(&quot;t&quot;, &quot;timetolive&quot;, 0, 100)
    * </pre>
    * 
    * @param [in] shortName
    *           argument shortcut
    * @param [in] fullName
    *           full name of argument
    * @param [in] minValue
    *           lowest possible value
    * @param [in] maxValue
    *           highest possible value
    * @param [in] defaultValues
    *           default value/values, if no argument was parsed
    */
   public FloatArgument(String shortName, String fullName, Double minValue,
         Double maxValue, Double... defaultValues) {
      super(shortName, fullName, defaultValues);
      _minValue = minValue;
      _maxValue = maxValue;

   }

   private Double _minValue = Double.MIN_VALUE;
   private Double _maxValue = Double.MAX_VALUE;

   /**
    * Function for processing one argument. Called by the parser.
    * @param [in] text value to be processed
    * @return processed value
    */
   @Override
   public Double parseOneArgument(String text) throws Exception {
      return Double.valueOf(text);
   }

   private static final String BAD_NUMBER_FORMAT_STRING =
         "Argument %s is not within specified boundaries.";

   /**
    * Function for validating one argument value.
    * @param [in] value value to be validated
    * @return ValidationResult object with the result
    */
   @Override
   public ValidationResult validateValue(Double value) {
      if ((value > _maxValue) || (value < _minValue)) {
         return ValidationResult.createInvalidResponse(String.format(
               BAD_NUMBER_FORMAT_STRING, getDefaultName()));
      }
      return ValidationResult.createValidResponse();
   }

   @Override
   Double[] getGenericArray() {
      return new Double[0];
   }

}
